//package com.snap.vseries;
//
//import com.orhanobut.logger.Logger;
//
//import java.io.IOException;
//
//import okhttp3.Call;
//import okhttp3.Callback;
//import okhttp3.Interceptor;
//import okhttp3.MediaType;
//import okhttp3.OkHttpClient;
//import okhttp3.Protocol;
//import okhttp3.Request;
//import okhttp3.Response;
//import okhttp3.ResponseBody;
//import okhttp3.logging.HttpLoggingInterceptor;
//
//public class RetryTest {
//
//    public static void main(String[] args) {
//        String mUrl = "https://www.baidu.com/";
////        String mUrl = "http://apicms.edengene.com.cn/api/tt/post";
//        OkHttpClient mClient = null;
//        HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
//        logging.setLevel(HttpLoggingInterceptor.Level.BODY);
//        mClient = new OkHttpClient.Builder()
//                .addInterceptor(new RetryIntercepter(3))//重试
////                .addInterceptor(logging)//网络日志
//                .addInterceptor(new TestInterceptor())//模拟网络请求
//                .build();
///*        mClient = new OkHttpClient.Builder()
//                .addInterceptor(logging)//网络日志
//                .addInterceptor(new RetryIntercepter(3))//重试
//                .build();*/
//        Request request = new Request.Builder()
//                .url(mUrl)
//                .build();
////        try {
////
////            Response response = mClient.newCall(request).execute();
////            System.out.println("onResponse:" + response.body().string());
////        } catch (IOException e) {
////            e.printStackTrace();
////        }
//
//        mClient.newCall(request).enqueue(new Callback() {
//            /*请求失败时的回调*/
//            @Override
//            public void onFailure(Call call, IOException e) {
//                Logger.e("onFailure:" + e.getMessage());
////                Log.e("onFailure: ", e.getMessage());
//                System.out.println("onFailure: " + e.getMessage());
//
//            }
//
//            /*请求成功时的回调*/
//            @Override
//            public void onResponse(Call call, Response response) throws IOException {
////                Logger.i("ApiData:" + response.body().string());
////                Log.e("ApiData:", response.body().string());
//                System.out.println("onResponse:" + response.body().string());
//
//            }
//        });
//    }
//
//    public static class TestInterceptor implements Interceptor {
//        @Override
//        public Response intercept(Chain chain) throws IOException {
////            String mUrl = "http://apicms.edengene.com.cn/api/tt/post";
//            String mUrl = "https://www.baidu.com/";
//
//            Request request = chain.request();
//            String url = request.url().toString();
//            System.out.println("url=" + url);
//            Response response = null;
//            if (url.equals(mUrl)) {
//                String responseString = "{\"message\":\"我是模拟的数据\"}";//模拟的错误的返回值
//                response = new Response.Builder()
//                        .code(400)
//                        .request(request)
//                        .message("hhh")
//                        .protocol(Protocol.HTTP_1_0)
//                        .body(ResponseBody.create(MediaType.parse("application/json"), responseString.getBytes()))
//                        .addHeader("content-type", "application/json")
//                        .build();
//            } else {
//                response = chain.proceed(request);
//            }
//            return response;
//        }
//    }
//}
